/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file           : main.h
 * @brief          : Header for main.c file.
 *                   This file contains the common defines of the application.
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2024 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C"
{
#endif

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx_hal.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "FreeRTOS.h"
#include "queue.h"
#include "subctrl.h"
#include "sys.h"

    /* USER CODE END Includes */

    /* Exported types ------------------------------------------------------------*/
    /* USER CODE BEGIN ET */
    typedef enum
    {
        kToneNone = 0,
        kToneL1 = 262,
        kToneL2 = 294,
        kToneL3 = 330,
        kToneL4 = 349,
        kToneL5 = 392,
        kToneL6 = 440,
        kToneL7 = 494,
        kToneL8 = 523,
        kToneM1 = 587,
        kToneM2 = 659,
        kToneM3 = 698,
        kToneM4 = 784,
        kToneM5 = 880,
        kToneM6 = 988,
        kToneM7 = 1047,
        kToneM8 = 1175,
        kToneH1 = 1319,
        kToneH2 = 1397,
        kToneH3 = 1568,
        kToneH4 = 1760,
        kToneH5 = 1976,
        kToneH6 = 2093,
        kToneH7 = 2349,
        kToneH8 = 2637,
    } buzzer_tone_t;

    typedef struct
    {
        QueueHandle_t queue;
        buzzer_tone_t tone;
        uint8_t state;
        uint16_t on_time;
        uint16_t off_time;
    } buzzer_t;

    typedef struct
    {
        sub_control_t sub_ctrl[SUBCTRL_NUM];
    } front_ctrl_t;

    /* USER CODE END ET */

    /* Exported constants --------------------------------------------------------*/
    /* USER CODE BEGIN EC */

    /* USER CODE END EC */

    /* Exported macro ------------------------------------------------------------*/
    /* USER CODE BEGIN EM */

    /* USER CODE END EM */

    /* Exported functions prototypes ---------------------------------------------*/
    void Error_Handler(void);

    /* USER CODE BEGIN EFP */
    void Buzzer_Run(buzzer_tone_t tone, uint16_t on_time, uint16_t off_time, uint8_t repeat);
    void Buzzer_Start(buzzer_tone_t tone, uint8_t *state);
    void Buzzer_Stop(uint8_t *state);
/* USER CODE END EFP */

/* Private defines -----------------------------------------------------------*/
#define SOURCE_CURR_Pin GPIO_PIN_7
#define SOURCE_CURR_GPIO_Port GPIOF
#define LED_Pin GPIO_PIN_9
#define LED_GPIO_Port GPIOF
#define ERR_Pin GPIO_PIN_0
#define ERR_GPIO_Port GPIOC
#define TRIGGER_Pin GPIO_PIN_1
#define TRIGGER_GPIO_Port GPIOC
#define INTL_TX_Pin GPIO_PIN_2
#define INTL_TX_GPIO_Port GPIOA
#define INTL_RX_Pin GPIO_PIN_3
#define INTL_RX_GPIO_Port GPIOA
#define SOURCE_CTRL_Pin GPIO_PIN_4
#define SOURCE_CTRL_GPIO_Port GPIOA
#define SOURCE_EN_Pin GPIO_PIN_5
#define SOURCE_EN_GPIO_Port GPIOA
#define SUB_TX_Pin GPIO_PIN_10
#define SUB_TX_GPIO_Port GPIOB
#define SUB_RX_Pin GPIO_PIN_11
#define SUB_RX_GPIO_Port GPIOB
#define KEY2_Pin GPIO_PIN_6
#define KEY2_GPIO_Port GPIOG
#define KEY2_EXTI_IRQn EXTI9_5_IRQn
#define KEY3_Pin GPIO_PIN_7
#define KEY3_GPIO_Port GPIOG
#define KEY3_EXTI_IRQn EXTI9_5_IRQn
#define KEY4_Pin GPIO_PIN_8
#define KEY4_GPIO_Port GPIOG
#define KEY4_EXTI_IRQn EXTI9_5_IRQn
#define KEY1_Pin GPIO_PIN_15
#define KEY1_GPIO_Port GPIOG
#define KEY1_EXTI_IRQn EXTI15_10_IRQn
#define EXTL_TX_Pin GPIO_PIN_6
#define EXTL_TX_GPIO_Port GPIOB
#define EXTL_RX_Pin GPIO_PIN_7
#define EXTL_RX_GPIO_Port GPIOB

/* USER CODE BEGIN Private defines */
#define LOG(format, ...)                                                                                               \
    do                                                                                                                 \
    {                                                                                                                  \
        if (log_level)                                                                                                 \
            ComExtern_Print(format, ##__VA_ARGS__);                                                                    \
    } while (0)
    /* USER CODE END Private defines */

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */
